// https://leetcode.cn/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/description/


func minimumOperations(nums []int) int {
    // n := len(nums)
	rec := make(map[int]int)
	for i := 0; i < len(nums); i++ {
		rec[nums[i]]++
	}
	ans := 0
	for len(nums) > 0 && len(rec) != len(nums) {
		for _, v := range(nums[:min(3, len(nums))]) {
			rec[v]--
			if rec[v] == 0 {
				delete(rec, v)
			}
		}
		ans++
        if len(nums) >= 3{
            nums = nums[3:]
        } else {
            nums = []int{}
        }
		
	}
	return ans
}